﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using chesslibrary.cs;
using System.Windows.Forms;
using System.Drawing;

namespace ChessGui
{
    public class image_chess
    {
        private ImageList thelist;
		public image_chess()
        {
			thelist=new ImageList();
	    	LoadImages();			
        }
        private void LoadImages()
		{
			thelist.ImageSize=new Size(45,45);
            thelist.Images.Add(System.Drawing.Image.FromFile("..\\..\\KW.png"));
            thelist.Images.Add(System.Drawing.Image.FromFile("..\\..\\KB.png"));
            thelist.Images.Add(System.Drawing.Image.FromFile("..\\..\\QW.png"));
            thelist.Images.Add(System.Drawing.Image.FromFile("..\\..\\QB.png"));
            thelist.Images.Add(System.Drawing.Image.FromFile("..\\..\\RW.png"));
            thelist.Images.Add(System.Drawing.Image.FromFile("..\\..\\RB.png"));
            thelist.Images.Add(System.Drawing.Image.FromFile("..\\..\\BW.png"));
            thelist.Images.Add(System.Drawing.Image.FromFile("..\\..\\BB.png"));
            thelist.Images.Add(System.Drawing.Image.FromFile("..\\..\\NW.png"));
            thelist.Images.Add(System.Drawing.Image.FromFile("..\\..\\NB.png"));
            thelist.Images.Add(System.Drawing.Image.FromFile("..\\..\\pW.png"));
            thelist.Images.Add(System.Drawing.Image.FromFile("..\\..\\pB.png"));
		}
        public Bitmap this[pieces_chess p]
		{
			get
			{
				return (Bitmap)thelist.Images[GetIndex(GetFilename(p))];
			}
		}
		private string GetFilename(pieces_chess p)
		{
			string filename;
            filename=p.ToString();
            if (p.IsOwnedBy(color_pieces.White))
			{
				return filename+"W";
			}
			else
			{
				return filename+"B";
			}
		}
        private int GetIndex(string s)
		{
			switch (s)
			{
				case "KW":
					return 0;
				case "KB":
					return 1;
				case "QW":
					return 2;
				case "QB":
					return 3;
				case "RW":
					return 4;
				case "RB":
					return 5;
				case "BW":
					return 6;
				case "BB":
					return 7;
				case "NW":
					return 8;
				case "NB":
					return 9;
				case "pW":
					return 10;
				case "pB":
					return 11;
				default:
					return 0;
			}
		}
     }
}
